package com.huo.thread.waitnotifydemo;

public class Demo2 extends  Thread {

    private WaitNotifyDemo demo;

    public Demo2(WaitNotifyDemo demo) {
        this.demo = demo;
    }

    @Override
    public void run() {
        synchronized (demo) {


                try {
                    if (demo.getValue() != 1) {
                        System.out.println(Thread.currentThread().getName() + "demo2正在执行：wait " + demo.getValue());
                        demo.wait();
                    } else {
                        demo.notify();
                        System.out.println(Thread.currentThread().getName() + "demo2正在执行：notify " + demo.getValue());

                    }

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

        }
        System.out.println(Thread.currentThread().getName() + "demo2 执行完毕");




    }
}
